package com.evil.admin.interseptor;

import com.evil.common.redis.util.RedisKeyUtil;
import com.evil.common.redis.util.RedisUtil;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
 * 缓存拦截器
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@Component
@AllArgsConstructor
public class CacheInterceptor implements HandlerInterceptor {

    private final RedisUtil redisUtil;

    @Override
    public void afterCompletion(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull Object handler, Exception exception) {
        // 清理 会话级别redis
        String requestUuid = RedisKeyUtil.requestUuid(request);
        redisUtil.vagueDel(RedisKeyUtil.requestUuidKey(requestUuid));
    }
}
